package cn.web.base.activemq;

import javax.jms.*;

public class MessageListener implements javax.jms.MessageListener {

    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            TextMessage textMsg = (TextMessage) message;
            System.out.println(this.getClass().getSimpleName() + ":接收到一个TextMessage对象");
            try {
                System.out.println("消息内容是：" + textMsg.getText());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        } else if (message instanceof ObjectMessage) {
            ObjectMessage objectMessage = (ObjectMessage) message;
            System.out.println(this.getClass().getSimpleName() + ":接收到一个ObjectMessage对象");
        } else if (message instanceof MapMessage) {
            MapMessage mapMessage = (MapMessage) message;
            System.out.println(this.getClass().getSimpleName() + ":接收到一个MapMessage对象");
        } else if (message instanceof BytesMessage) {
            BytesMessage bytesMessage= (BytesMessage) message;
            System.out.println(this.getClass().getSimpleName() + ":接收到一个BytesMessage对象");
        } else if (message instanceof StreamMessage) {
            StreamMessage streamMessage = (StreamMessage) message;
            System.out.println(this.getClass().getSimpleName() + ":接收到一个StreamMessage对象");

        }
    }
}
